import Request from "@/common/utils/request/index";
import {
  CalculatePriceDTO,
  TradeinCheckOutDto,
} from "@/types/model/tradein/dtos/tradein.dto";
import {
  TradeInOrderDetailVO,
  TradeInReceiptDataVO,
} from "@/types/model/tradein/vos/tradein.vo";

enum Api {
  CalculatePrice = "/jeecgboot/posTradein/calculatePrice",
  TradeinCheckout = "/jeecgboot/posTradein/tradeInCheckout",
  GetTradeinOrderDetail = "/jeecgboot/posTradein/getOrderDetail",
  GetCheckResultByPurchaseItem = "/jeecgboot/posTradein/getCheckResultByPurchaseItem",
  GetTradeInReceiptData = "/jeecgboot/posTradein/getTradeInReceiptData",
  ChangeOrderStatus = "/jeecgboot/posTradein/changeOrderStatus",
  CompleteOrder = "/jeecgboot/posTradein/completeOrder",
  CancelOrder = "/jeecgboot/posTradein/cancelOrder",
}

export const calculatePrice = (params: CalculatePriceDTO) => {
  return Request.getInstance().send<number>({
    url: Api.CalculatePrice,
    method: "POST",
    data: params,
  });
};

export const tradeinCheckout = (params: TradeinCheckOutDto) => {
  return Request.getInstance().send<any>({
    url: Api.TradeinCheckout,
    method: "POST",
    data: params,
  });
};

export const getPurchaseOrderDetail = (id: string) => {
  return Request.getInstance().send<TradeInOrderDetailVO>({
    url: Api.GetTradeinOrderDetail,
    method: "GET",
    params: { id },
  });
};

export const getCheckResultByPurchaseItem = (id: string) => {
  return Request.getInstance().send({
    url: Api.GetCheckResultByPurchaseItem,
    method: "GET",
    params: {
      itemId: id,
    },
  });
};

export const getTradeInReceiptData = (orderId: string) => {
  return Request.getInstance().send<TradeInReceiptDataVO>({
    url: Api.GetTradeInReceiptData,
    method: "GET",
    params: {
      orderId,
    },
  });
};

export const changeOrderStatus = (params: {
  orderId: string;
  status: string;
  bizType: String;
}) => {
  return Request.getInstance().send({
    url: Api.ChangeOrderStatus,
    method: "POST",
    data: params,
  });
};

export const completeOrder = (orderId: string) => {
  return Request.getInstance().send({
    url: Api.CompleteOrder,
    method: "POST",
    data: { orderId },
  });
};

export const cancelOrder = (orderId: string) => {
  return Request.getInstance().send({
    url: Api.CancelOrder,
    method: "POST",
    data: { orderId },
  });
};
